/**
 * 文件模型
 *
 * Created by snowingsea on 2020/02/06.
 */
const mongoose = require('mongoose');
const mongooseLeanDefaults = require('mongoose-lean-defaults');
const schemaDefinition = require('./schema/file');
const schemaInstance = mongoose.Schema(schemaDefinition);
schemaInstance.plugin(mongooseLeanDefaults.default);
schemaInstance.index({ versionId: 1, path: 1 });
schemaInstance.set('autoIndex', false);
const modelInstance = mongoose.model('file', schemaInstance);
mongoose.connection.on('open', () => modelInstance.syncIndexes().catch(() => {}));

/**
 * Export model definition object.
 */
module.exports = modelInstance;
